<html>

<head>

</head>

<body>

<div>
    <!--<input type="text" speech x-webkit-speech onwebkitspeechchange="alert(this.value)" />-->
    <input type="text" speech x-webkit-speech />
</div>



问:<input type="text" id="robot" onkeypress="showHint(this.value)"/>

<input type="button" value="发送" onclick="Send(document.getElementById('robot').value)"/> 当键盘敲击回车时发送



<p>答: <span id="txtHint"></span></p>



<button onclick="testAudio()">
    我要测试语音识别哈哈哈哈哈哈哈哈哈
</button>

<script>

    var xmlHttp,
            audioHttp;

    function showHint(str)

    {

        if (event.keyCode==13)

        {

            Send(str);

        }

    }

    function Send(str)

    {

        if (str.length==0)

        {

            document.getElementById("txtHint").innerHTML="";

            return;

        }

        xmlHttp=GetXmlHttpObject()

        if (xmlHttp==null)

        {

            alert ("您的浏览器不支持AJAX！");

            return;

        }

//        var url="http://www.tuling123.com/openapi/api?key=e825286159f9f57db1b597995d72ae2b";
        var url="http://www.tuling123.com/openapi/api?key=9078f28c18414afabe679d3cb41f38a4";

        url=url+"&info="+str;

        url=url+"&userid=1234" ;

        xmlHttp.onreadystatechange=stateChanged;

        xmlHttp.open("GET",url,true);

        xmlHttp.send(null);

        document.getElementById("robot").value="";

    }

    function stateChanged()

    {

        if (xmlHttp.readyState==4)

        {

            var msg=eval('(' + xmlHttp.responseText + ')');



            document.getElementById("txtHint").innerHTML=msg.text;

        }

    }

    function GetXmlHttpObject()

    {

        var xmlHttp=null;

        try

        {

            // Firefox, Opera 8.0+, Safari

            xmlHttp=new XMLHttpRequest();

        }

        catch(e)

        {

            // Internet Explorer

            try

            {

                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

            }

            catch (e)

            {

                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

            }

        }

        return xmlHttp;

    }


    function testAudio(){
        audioHttp = GetXmlHttpObject();
        if (xmlHttp==null)

        {

            alert ("您的浏览器不支持AJAX！");

            return;

        }

//        var url="http://www.tuling123.com/openapi/api?key=e825286159f9f57db1b597995d72ae2b";
        var url="http://api.lingban.cn/tts/synthesizer?access_token=ACCESS_TOKENcontent-type=application/json;charset=UTF-8";

        url=url+"&info="+str;

        url=url+"&userid=1234" ;

        xmlHttp.onreadystatechange=stateChanged;

        xmlHttp.open("GET",url,true);

        xmlHttp.send(null);

        document.getElementById("robot").value="";
    }

</script>

</body>

</html>